package com.ycy.temperature.view.base;

import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

//import io.realm.Realm;

public abstract class BaseFragment extends Fragment implements View.OnClickListener, Handler.Callback {
    protected abstract int getRes();

    protected abstract void init(View view);

    protected abstract void setData(View view);

    protected static final int TYPE_REFRESH = 0;
    protected static final int TYPE_LoadMORE = 1;
    protected View view = null;
    //  protected Realm realm;
    protected Handler bkThreadHandler;
    protected Handler mainThreadHandler;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        view = inflater.inflate(getRes(), container, false);

        HandlerThread handlerThread = new HandlerThread("BackgroundThreadHandler_Fragment");
        handlerThread.start();

        bkThreadHandler = new Handler(handlerThread.getLooper(), this);
        mainThreadHandler = new Handler(Looper.getMainLooper(), this);
        init(view);
        setData(view);
        return view;
    }

    @SuppressWarnings("unchecked")
    protected <T extends View> T r2v(View view, int resId) {
        return (T) view.findViewById(resId);
    }

    @Override
    public boolean handleMessage(Message msg) {
        return false;
    }

}
